package evaluacredito.web;

import static org.junit.Assert.fail;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import evaluacredito.dao.UsuarioDAOImpl;
import evaluacredito.excepcion.DAOExcepcion;
import evaluacredito.excepcion.LoginExcepcion;
import evaluacredito.modelo.Usuario;

/**
 * Servlet implementation class Index
 */
public class Index extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Index() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String nomUsu = request.getParameter("nomUsu");
		String clave = request.getParameter("clave");

		Usuario usuario = new Usuario();
		usuario.setNomUsu(nomUsu);
		usuario.setClave(clave);
		System.out.println(nomUsu);
		System.out.println(clave);

		try {
			UsuarioDAOImpl usuarioDAOImpl = new UsuarioDAOImpl();
			usuarioDAOImpl.validar(usuario.getNomUsu(), usuario.getClave());
			System.out.println("Usuario " + " " + usuario.getNomUsu() + " "
					+ "Clave" + " " + usuario.getClave() + " " + "Correctos");
			response.sendRedirect("ListarPersonaServlet");

		} catch (DAOExcepcion e) {
			fail(e.getMessage());
		} catch (LoginExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
